export default {
	getfriends(list,myfirend){
		return list.filter((el,index)=>{
			let myindex = myfirend.findIndex((myel)=>{
				return myel.frienid == el.id
			})
			if(myindex!=-1){
				let imgurl = `../../static/images/userimg/pic_${el.imgurl}.jpg`
				el.imgurl = imgurl
				el.time = gettime(el.time)
				return el
			}
		})
	},
	gettime,
	dirnametime(time){
		let d = new Date(time)
		let D = d.getDate();
		let M = d.getMonth() + 1;
		let Y = d.getFullYear();
		if(D< 10){
			D = '0'+D
		}
		if(M<10){
			M = '0'+M
		}
		return `${Y}${M}${D}`
	},
	spacetime(old,now){
		old = new Date(old)
		now = new Date(now)
		let told = old.getTime();
		let tnow = now.getTime();
		if(tnow - told > 1000*60*5){
			return now
		}else{
			return ''
		}
	},
	sendspacetime(old,now){
		old = new Date(old)
		now = new Date(now)
		let told = old.getTime();
		let tnow = now.getTime();
		
		if( tnow -told > 10){
			return now
		}else{
			return ''
		}
	},
	debounce(func,delay){//防抖函数
		var timer;
		return function(){
			if(timer!=null){
				clearTimeout(timer);
			}
			let args = arguments;
			let _this = this
			timer = setTimeout(function(){
				timer = null
				func.apply(_this,args)
			},delay)
		}
	}
}
function gettime(time){
		let d = new Date(time)
		let D = d.getDate();
		let M = d.getMonth() + 1;
		let Y = d.getFullYear();
		let h = d.getHours();
		let m = d.getMinutes();
		
		let n = new Date()
		let nD = n.getDate();
		let nM = n.getMonth() + 1;
		let nY = n.getFullYear();
		let nh = n.getHours();
		let nm = n.getMinutes();
		if(h< 10){
			h = '0'+h
		}
		if(m<10){
			m = '0'+m
		}
		if(D == nD && M == nM && Y == nY){
			return `${h}:${m}`
		}else if( M == nM && Y == nY && nD-D ==1){
			return `昨天${h}:${m}`
		}else{
			return ` ${Y}/${M}/${D} ${h}:${m}`
		}
		
	}